package com.qqhf.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@EnableOpenApi
@Configuration
public class Swagger3Config {

    // 配置文件中配置是否开启Swagger
    //@Value("${swagger.enable}")
    //private Boolean SwaggerEnable;

    @Bean
    public Docket createRestApi() { //swagger设置基本信息，要解析的接口及路径等

        return new Docket(DocumentationType.OAS_30)
                //添加文档信息
                .apiInfo(apiInfo())
                .select()
                //选择要显示的包 如果是下面的写法则会将所有的接口都会展示出来 无论你有没有写注解
                .apis(RequestHandlerSelectors.basePackage("com.qqhf.hitfood.controller"))
                //而这种写法则是将所有的有注解的接口展示出来
                //.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();

                //是否启用Swagger
                //.enable(SwaggerEnable);
    }

    private ApiInfo apiInfo() { //接口文档信息
        return new ApiInfoBuilder()
                .title("'工大饮食'的接口文档")
                .description("更多请咨询服务开发者湫湫")
                .contact(new Contact("qiuqiu", "https://www.baidu.com/", "kkhhkk@126.com"))
                .version("1.0")
                .build();
    }
}
